package com.example.interview.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-04-08
 * Time:20:46
 * Text：
 */
@RestController
public class RedisController {
    private  static final String _Redis_Key = "我爱Redis";

    @Autowired
    private RedisTemplate redisTemplate;

    @RequestMapping("/setval")
    public void setVal(String val){
        redisTemplate.opsForValue()               //时间单位秒
                .set(_Redis_Key,val,1000, TimeUnit.SECONDS);
    }
    @RequestMapping("/getval")
    public String getVal(){
        return (String)redisTemplate.opsForValue().get(_Redis_Key);
    }

}
